package com.xinyu.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinyu.domain.Operation;
import com.xinyu.mapper.OperationMapper;
import com.xinyu.service.IOperationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinyu.vo.BaseResult;
import com.xinyu.vo.OperationRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author l
 * @since 2025-02-20
 */
@Service
public class OperationServiceImpl extends ServiceImpl<OperationMapper, Operation> implements IOperationService {
    @Autowired
    private OperationMapper operationMapper;

    @Override
    public BaseResult queryByPage(OperationRequest operationRequest) {
        Page<Operation> page = new Page<>(operationRequest.getPage(), operationRequest.getRows());
        page.addOrder(OrderItem.desc("operationTime"));
        // 执行分页查询
        IPage<Operation> result = operationMapper.selectPage(page, null);

        return BaseResult.ok(result.getRecords(),(int)result.getTotal());
    }
}
